# -*- coding: utf-8 -*-
from odoo import models, fields, api


class GymInvoice(models.Model):
    _name = 'gym.invoice'

    name = fields.Char()
    start_date = fields.Date(string='開始時間', required=True)
    end_date = fields.Date(string='結束時間', required=True)

    def active_to_print(self):
        data = {
            'start': self.start_date,  # wizard的開始範圍
            'end': self.end_date , # wizard的結束範圍
        }
        return self.env['report'].get_action([], 'alltop_401tax.gym_invoice_report', data)

    def active_to_pivot(self):
        view = self.env.ref('alltop_401tax.gym_invoice_401_pivot_report')
        domain = [('date_invoice', '>=', self.start_date), ('date_invoice', '<=', self.end_date), ('state', '=', 'paid')]
        return {
            'name': '%s到 %s 的401報表' % (self.start_date, self.end_date),
            'domain': domain,
            'res_model': 'account.invoice',
            'type': 'ir.actions.act_window',
            'view_id': view.id,
            'view_mode': 'pivot',
            'view_type': 'pivot',
        }



class ReportGymInvoice(models.AbstractModel):
    _name = 'report.alltop_401tax.gym_invoice_report'

    def render_html(self, data=None):
        start = data['start']
        end = data['end']

        docargs = {
            'start': start,
            'end': end

        }
        return self.env['report'].render('alltop_401tax.gym_invoice_report', docargs)
